<template>
  <view>
    <!-- 顶部大图 -->
    <view class="album-bg">
      <image :src="album.cover" mode="widthFix"></image>
      <view class="album-info">
        <view class="album-name">{{album.name}}</view>
        <view class="album-btn">关注专辑</view>
      </view>
    </view>
    <!-- 专辑作者 -->
    <view class="album-author">
      <view class="album-author-info">
        <image :src="album.user.avatar" mode="widthFix"></image>
        <view class="author-name">{{album.user.name}}</view>
      </view>
      <view class="album-author-desc">
        <text>{{album.desc}}</text>
      </view>
    </view>
    <!-- 列表 -->
    <view class="album-list">
      <view class="album-item" v-for="(item,index) in wallpaper" :key="item.id">
        <go-detail :list="wallpaper" :index="index">
          <image :src="item.thumb+item.rule.replace('$<Height>',360)"
            mode="aspectFill"></image>
        </go-detail>
      </view>
    </view>
  </view>
</template>

<script>
import goDetail from '@/components/GoDetail'
export default {
  data() {
    return {
      // 请求参数
      params: {
        limit: 30,
        order: 'new',
        skip: 0,
        // 值为1 表示第一次请求 数据有album对象
        // 值为0 表示不是第一次请求 数据没有album对象
        first: 1
      },
      id: 1,
      album: {},
      wallpaper: [],
      hasMore: true
    }
  },
  components: {
    goDetail
  },
  onLoad(options) {
    this.id = options.id
    // this.id = '5e5cf679e7bce739db1281e4'
    this.getList()
  },
  // 页面触底
  onReachBottom() {
    if (this.hasMore) {
      this.params.skip += this.params.limit
      this.params.first = 0
      this.getList()
    } else {
      uni.showToast({
        title: '没有更多了~',
        icon: 'none'
      })
    }
  },
  methods: {
    // 获取数据
    async getList() {
      const res = await this.request({
        url: `http://157.122.54.189:9088/image/v1/wallpaper/album/${this.id}/wallpaper`,
        data: this.params
      })
      // 顶部大图只需加载一次，下面的图片列表根据触底可能会加载多次
      if (Object.keys(this.album).length === 0) {
        this.album = res.res.album
      }
      if (res.res.wallpaper.length === 0) {
        this.hasMore = false
        uni.showToast({
          title: '没有更多了~',
          icon: 'none'
        })
        return
      }
      this.wallpaper = [...this.wallpaper, ...res.res.wallpaper]
    }
  }
}
</script>

<style lang="scss" scoped>
// 顶部大图
.album-bg {
  position: relative;
  .album-info {
    position: absolute;
    bottom: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 80rpx;
    color: #fff;
    padding: 0 15rpx;
    .album-name {
      font-size: 36rpx;
    }

    .album-btn {
      width: 152rpx;
      height: 55rpx;
      line-height: 55rpx;
      text-align: center;
      border-radius: 8rpx;
      background-color: $theme-color;
    }
  }
}
// 作者
.album-author {
  padding: 10rpx;
  .album-author-info {
    display: flex;
    align-items: center;
    padding: 10rpx;
    image {
      width: 50rpx;
    }

    .author-name {
      margin-left: 15rpx;
      color: #000;
    }
  }
}
// 图片列表
.album-list {
  display: flex;
  flex-wrap: wrap;
  .album-item {
    width: 33.33%;
    border: 3rpx solid #fff;
    image {
      height: 160rpx;
    }
  }
}
</style>